package gold.digger;

import java.util.Random;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC384 {

    /*
     * @param 此题目直接用别人代码，自己只理解思想
     * @return:
     */
    class Solution {
        private int[] orgn;
        private int[] cur;

        public Solution(int[] nums) {
            orgn = nums;
        }

        /**
         * Resets the array to its original configuration and return it.
         */
        public int[] reset() {
            return orgn;
        }

        /**
         * Returns a random shuffling of the array.
         */
        public int[] shuffle() {
            int len = orgn.length;
            cur = new int[len];
            for (int i = 0; i < len; i++)
                cur[i] = orgn[i];
            int randomSwapIndex;//记录要交换元素的位置
            int temp; //记录要交换的值
            Random ran = new Random();
            for (int i = len - 1; i >= 1; i--) {
                randomSwapIndex = ran.nextInt(i + 1);
                temp = cur[randomSwapIndex];
                cur[randomSwapIndex] = cur[i];
                cur[i] = temp;
            }
            return cur;
        }

    }

    public static void main(String[] args) {
        LC384 an = new LC384();
    }
}
